import Vue from 'vue';
import Vuex from 'vuex';
import { api } from '../Axios';
import _ from 'lodash';

import { Recipe } from '../assets/items'; //引入配方对象

Vue.use(Vuex);

export default new Vuex.Store({
  modules: {},
  state: {
    recipes: [], //配方列表
  },
  getters: {
    // getValue: (state) => (key) => {
    //   return state[key];
    // },
    getRecipeById: (state) => {
      return (id) => {
        let item = _.find(state.recipes, { id: id });
        return item || null;
      };
    },
  },
  mutations: {
    ADD_RECIPE(state, recipe) {
      let item = new Recipe(recipe);
      state.recipes.push(item);
    }, //添加配方：配方对象
  },
  actions: {
    fetchCusInfo: (ctx, payload) => {},
    fetchItems: (ctx, payload) => {},
  },
});
